home *** CD-ROM | disk | FTP | other *** search
-
- /****************************************************************************
-
- X6502.H
-
- - extern declarations of opcode handler routines
-
- 01/23/88 created
-
- 06/09/88 19:50
-
- ****************************************************************************/
-
- /* exit codes from interpreter */
- #define EXIT_BREAK 0
- #define EXIT_INVALID 1
- #define EXIT_ALTKEY 2
-
- /* opcode for RTS */
- #define OP_RTS 0x4E75
-
- /* opcode to jump to interrupt vector */
- #define OP_INT 0x60E8
-
- /* opcode for JMP long */
- #define OP_JMP 0x4EF9
-
- /* first 2 words of dispatcher */
- #define OP_EMUL 0x1A99
-
- /* status bits of the P register: (6502) NV_BDIZC */
-
- #define NBIT 0x80
- #define VBIT 0x40
- #define BBIT 0x10
- #define DBIT 0x08
- #define IBIT 0x04
- #define ZBIT 0x02
- #define CBIT 0x01
-
- /* status bits of the CCR register: (68000) ___XNZVC */
-
- #define BITV 0x02
- #define BITN 0x08
- #define BITZ 0x04
- #define BITC 0x01
- #define BITX 0x10
-
- /* convert P register NV_BDIZC to CCR register BDIXNZVC */
- #define P_to_ST \
- move.b bRegP(arEMUL),drDATA \
- btst #4,drDATA \
- sne bB(arEMUL) \
- btst #3,drDATA \
- sne drST \
- ext.w drST \
- ext.l drST \
- btst #2,drDATA \
- sne bI(arEMUL) \
- btst #6,drDATA \
- sne bV(arEMUL) \
- btst #0,drDATA \
- sne drC \
- andi.b #ZBIT,drDATA \
- seq drST \
- andi.b #0x7F,drST \
- move.b bRegP(arEMUL),drDATA \
- andi.b #0x80,drDATA \
- or.b drDATA,drST \
- ext.w drST
-
- /* convert CCR register BDIXNZVC to P register NV_BDIZC */
- #define ST_to_P \
- move.b bB(arEMUL),drEA \
- andi.w #BBIT,drEA \
- tst.l drST \
- smi drDATA \
- andi.w #DBIT,drDATA \
- or.b drDATA,drEA \
- move.b bI(arEMUL),drDATA \
- andi.w #IBIT,drDATA \
- or.b drDATA,drEA \
- move.b bV(arEMUL),drDATA \
- andi.w #VBIT,drDATA \
- or.b drDATA,drEA \
- move.b drC,drDATA \
- andi.w #CBIT,drDATA \
- or.b drDATA,drEA \
- move.b drST,drDATA \
- seq drDATA \
- andi.b #ZBIT,drDATA \
- or.b drDATA,drEA \
- lsr.w #1,drST \
- andi.b #0x80,drST \
- or.b drST,drEA \
- ori.b #0x20,drEA \
- move.b drEA,bRegP(arEMUL)
-
- /* data register definitions of 6502 registers */
-
- #define drDATA D0
- #define drA D1
- #define drX D2
- #define drY D3
- #define drSP D4
- #define drC D5
- #define drST D6
- #define drEA D7
-
- /* pointer to mem[ea] and otherwise all purpose register*/
- #define arEA A0
-
- /* pointer to current 6502 opcode */
- #define arPC A1
-
- /* pointer to the dispatcher, from which all other addresses are calced */
- #define arEMUL A2
-
- /* pointer to array of read status bytes */
- #define arRSTAT A3
-
- /* pointer to array of write status bytes */
- #define arWSTAT A4
-
- /* arEMUL + 4, pointer to self modifying jump vector in dispatcher */
- #define arEMVEC A5
-
- /* pointer to the frame (local variables) */
- #define LOCAL A6
-
- /* the stack pointer, for some reason, not defined by Megamax */
- #define SP A7
-
- /* quickly save and restore 6502 variables */
- #define SAVEREGS movem.l D0-D7/A0-A5,-(SP)
- #define LOADREGS movem.l (SP)+,D0-D7/A0-A5
-
- /* finished executing an opcode, go to dispatch routine */
- #define DISPATCH jmp (arEMUL)
-
- #define UNUSED jmp (arEMUL)
-
- /* Effective Address calculation macros */
-
- /* (zp,X) 44 cycles */
- /* dc.w 0x0F08,0x0001 ; movep.w 1(arEA),drEA */
- #define EA_zpXind \
- clr.w drEA \
- move.b (arPC)+,drEA \
- add.b drX,drEA \
- move.l drEA,arEA \
- dc.w 0x0F08,0x0001 \
- move.b (arEA),drEA \
- move.l drEA,arEA
-
- /* zp 16 cycles */
- #define EA_zp \
- clr.w drEA \
- move.b (arPC)+,drEA \
- move.l drEA,arEA
-
- /* same as zp, except used before a LDA to save 4 cycles */
- #define EA_Azp \
- move.b (arPC)+,drA \
- move.l drA,arEA
-
- /* same as zp, except used before a LDX to save 4 cycles */
- #define EA_Xzp \
- move.b (arPC)+,drX \
- move.l drX,arEA
-
- /* same as zp, except used before a LDY to save 4 cycles */
- #define EA_Yzp \
- move.b (arPC)+,drY \
- move.l drY,arEA
-
- /* abs 32 cycles */
- /* dc.w 0x0F09,0x0001 ; movep.w 1(arPC),drEA */
- #define EA_abs \
- dc.w 0x0F09,0x0001 \
- move.b (arPC),drEA \
- addq.w #2,arPC \
- move.l drEA,arEA
-
- /* abs,X 36 cycles */
- /* dc.w 0x0F09,0x0001 ; movep.w 1(arPC),drEA */
- #define EA_absX \
- dc.w 0x0F09,0x0001 \
- move.b (arPC),drEA \
- addq.w #2,arPC \
- add.w drX,drEA \
- move.l drEA,arEA
-
- /* abs,Y 36 cycles */
- /* dc.w 0x0F09,0x0001 ; movep.w 1(arPC),drEA */
- #define EA_absY \
- dc.w 0x0F09,0x0001 \
- move.b (arPC),drEA \
- addq.w #2,arPC \
- add.w drY,drEA \
- move.l drEA,arEA
-
- /* (zp),Y 44 cycles */
- /* dc.w 0x0F08,0x0001 ; movep.w 1(arEA),drEA */
- #define EA_zpYind \
- clr.w drEA \
- move.b (arPC)+,drEA \
- move.l drEA,arEA \
- dc.w 0x0F08,0x0001 \
- move.b (arEA),drEA \
- add.w drY,drEA \
- move.l drEA,arEA
-
- /* zp,X 20 cycles */
- #define EA_zpX \
- clr.w drEA \
- move.b (arPC)+,drEA \
- add.b drX,drEA \
- move.l drEA,arEA
-
- /* zp,X 16 cycles, before a LDA */
- #define EA_AzpX \
- move.b (arPC)+,drA \
- add.b drX,drA \
- move.l drA,arEA
-
- /* zp,Y 20 cycles */
- #define EA_zpY \
- clr.w drEA \
- move.b (arPC)+,drEA \
- add.b drY,drEA \
- move.l drEA,arEA
-
- /* $6704 (beq.s *+4) is used because Megamax doesn't have local labels */
- #define ReadService \
- cmpi.w #0xC000,drEA \
- dc.w 0x650A \
- move.b 0(arRSTAT,drEA),drDATA \
- dc.w 0x6704 \
- jsr lReadDisp(arEMUL)
-
- #define WriteService \
- move.b 0(arWSTAT,drEA),drDATA \
- dc.w 0x6A06 \
- move.w drST,-(SP) \
- jmp lWriteDisp(arEMUL)
-
- #define WriteAService \
- move.b 0(arWSTAT,drEA),drDATA \
- dc.w 0x6A06 \
- move.w drA,-(SP) \
- jmp lWriteDisp(arEMUL)
-
- #define WriteXService \
- move.b 0(arWSTAT,drEA),drDATA \
- dc.w 0x6A06 \
- move.w drX,-(SP) \
- jmp lWriteDisp(arEMUL)
-
- #define WriteYService \
- move.b 0(arWSTAT,drEA),drDATA \
- dc.w 0x6706 \
- move.w drY,-(SP) \
- jmp lWriteDisp(arEMUL)
-
- /* offsets of assembler level variables, offset from arEMUL */
-
- #define cbGLOBALS 162
-
- #define JumpVecs -162
- #define Jump0 -162
- #define Jump1 -158
- #define Jump2 -154
- #define Jump3 -150
- #define Jump4 -146
-
- #define SaveRegs -98
-
- #define bNMI -42
- #define bIRQ -41
- #define bIRQmask -40
- #define bB -39
- #define xxxbD -38
- #define bI -37
- #define bV -36
- #define bCX -35
-
- /* these guys pass the 6502 registers back and forth to the monitor */
- #define bRegA -34
- #define bRegX -33
- #define bRegY -32
- #define bRegP -31
- #define wRegSP -30
- #define wRegPC -28
- #define wEA -26
-
- /* when exiting interpreter, this code tells us why */
- #define wExitCode -24
-
- #define lInterrupt -22
- #define lIntVec -20
-
- #define lWriteDisp -16
- #define lReadDisp -8
-
- #define cbDISPATCH 6
-
- /* these offsets give the starting byte of each routine in the page */
- /* opcodes are at byte 6, read routines as byte $80, in opcode 0 to $7F */
- /* and write routines also at byte $80, in opcodes $80 to $FF */
- #define iOpcodes 6
- #define iRead 0x80
- #define iWrite 0x8080
-
- extern int (*vec_6502[257])(); /* pointer to 256 opcode routines and dummy */
-
- extern Lemul(), Lglobals();
-
- extern RegA4();
-
- /* when emulation is about to being, these routines hook in VBIs, etc... */
- extern (*pHookIn)(), (*pUnHook)();
-
- /* tell Megamax that the emulation routines will be found in inline code: */
- extern
- op00(), op01(), op02(), op03(), op04(), op05(), op06(), op07(),
- op08(), op09(), op0A(), op0B(), op0C(), op0D(), op0E(), op0F(),
- op10(), op11(), op12(), op13(), op14(), op15(), op16(), op17(),
- op18(), op19(), op1A(), op1B(), op1C(), op1D(), op1E(), op1F(),
- op20(), op21(), op22(), op23(), op24(), op25(), op26(), op27(),
- op28(), op29(), op2A(), op2B(), op2C(), op2D(), op2E(), op2F(),
- op30(), op31(), op32(), op33(), op34(), op35(), op36(), op37(),
- op38(), op39(), op3A(), op3B(), op3C(), op3D(), op3E(), op3F(),
- op40(), op41(), op42(), op43(), op44(), op45(), op46(), op47(),
- op48(), op49(), op4A(), op4B(), op4C(), op4D(), op4E(), op4F(),
- op50(), op51(), op52(), op53(), op54(), op55(), op56(), op57(),
- op58(), op59(), op5A(), op5B(), op5C(), op5D(), op5E(), op5F(),
- op60(), op61(), op62(), op63(), op64(), op65(), op66(), op67(),
- op68(), op69(), op6A(), op6B(), op6C(), op6D(), op6E(), op6F(),
- op70(), op71(), op72(), op73(), op74(), op75(), op76(), op77(),
- op78(), op79(), op7A(), op7B(), op7C(), op7D(), op7E(), op7F(),
- op80(), op81(), op82(), op83(), op84(), op85(), op86(), op87(),
- op88(), op89(), op8A(), op8B(), op8C(), op8D(), op8E(), op8F(),
- op90(), op91(), op92(), op93(), op94(), op95(), op96(), op97(),
- op98(), op99(), op9A(), op9B(), op9C(), op9D(), op9E(), op9F(),
- opA0(), opA1(), opA2(), opA3(), opA4(), opA5(), opA6(), opA7(),
- opA8(), opA9(), opAA(), opAB(), opAC(), opAD(), opAE(), opAF(),
- opB0(), opB1(), opB2(), opB3(), opB4(), opB5(), opB6(), opB7(),
- opB8(), opB9(), opBA(), opBB(), opBC(), opBD(), opBE(), opBF(),
- opC0(), opC1(), opC2(), opC3(), opC4(), opC5(), opC6(), opC7(),
- opC8(), opC9(), opCA(), opCB(), opCC(), opCD(), opCE(), opCF(),
- opD0(), opD1(), opD2(), opD3(), opD4(), opD5(), opD6(), opD7(),
- opD8(), opD9(), opDA(), opDB(), opDC(), opDD(), opDE(), opDF(),
- opE0(), opE1(), opE2(), opE3(), opE4(), opE5(), opE6(), opE7(),
- opE8(), opE9(), opEA(), opEB(), opEC(), opED(), opEE(), opEF(),
- opF0(), opF1(), opF2(), opF3(), opF4(), opF5(), opF6(), opF7(),
- opF8(), opF9(), opFA(), opFB(), opFC(), opFD(), opFE(), opFF(),
- opXX();
-
-
-